<%@ page import="cn.yunhe.news.dao.IBoardDao" %>
<%@ page import="cn.yunhe.news.dao.impl.BoardDao" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.yunhe.news.entity.Board" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.yunhe.news.FenYe" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        .main {
            width: 100%;
            height: 100%;
            margin: 0px auto;
        }

        .main_main {
            width: 70%;
            height: 100%;
            margin: 0px auto;
            text-align: center;
            font-size: 25px;
        }

        .main_top {
            width: 100%;
            height: 20%;
            margin-top: 50px;
        }

        input[type="text"] {
            height: 40px;
            font-size: 25px;
        }

        input[type="submit"] {
            height: 40px;
            font-size: 20px;
        }

        table {
            text-align: center;
            width: 500px;
            font-size: 20px;
        }
    </style>
</head>
<body background="pic/ManBgroud.gif">
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    String keyword = "";
    if (request.getAttribute("keyword") != null) {
        keyword = (String) request.getAttribute("keyword");
    }
%>
<div class="main">
    <div class="main_main">
        <div class="main_top">
            <form action="addzt_action.jsp" method="post">
                请输入要增加的主题名字:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="bname">
                <input type="submit" value="添加">
            </form>
            <form action="addselect.jsp" method="post">
                请输入关键字:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="keyword" value="<%=keyword%>">
                <input type="submit" value="搜索">
            </form>
        </div>
        <div class="main_buttom">
            <table border="1" cellspacing="0" cellpadding="0" align="center">
                <tr>
                    <th>主题编号</th>
                    <th>主题名称</th>
                </tr>
                <%
                    String pageIn = (String) request.getAttribute("pageIndex");
                    if (pageIn == null) {
                        pageIn = "1";
                    }
                    int pageIndex = Integer.parseInt(pageIn);

                    IBoardDao boardDao = new BoardDao();

                    //总条数
                    int count = boardDao.allCount();
                    //总页数
                    int pageSize = FenYe.pageSize(count, FenYe.pageNum);

                    if (pageIndex < 1) {
                        pageIndex = 1;
                    }
                    if (pageIndex > pageSize) {
                        pageIndex = pageSize;
                    }

                    List<Board> allList = new ArrayList<Board>();
                    //全部查
                    List<Board> boardList = boardDao.boardFList(FenYe.pageNum, pageIndex);

                    List<Board> keyList = (List<Board>) request.getAttribute("keyList");

                    if (keyList != null) {
                        allList = keyList;
                    } else {
                        allList = boardList;
                    }


                    for (Board b : allList) {
                %>
                <tr>
                    <td>
                        <%=b.getBid()%>
                    </td>
                    <td>
                        <%=b.getBname()%>
                    </td>
                </tr>
                <%
                    }
                %>
                <tr>
                    <td colspan="3">
                        <a href="addselect.jsp?pageIndex=1&&keyword=<%=keyword%>">首页</a>
                        <a href="addselect.jsp?pageIndex=<%=pageIndex-1%>&&keyword=<%=keyword%>">上一页</a>
                        <a href="addselect.jsp?pageIndex=<%=pageIndex+1%>&&keyword=<%=keyword%>">下一页</a>
                        <a href="addselect.jsp?pageIndex=<%=pageSize%>&&keyword=<%=keyword%>">尾页</a>
                    </td>
            </table>
        </div>
    </div>
</div>
</body>
</html>
